﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form3_SetMeterSpecification : Form
    {
        public Form1 f1;
        public Form3_SetMeterSpecification()
        {
            InitializeComponent();
        }

        public Form3_SetMeterSpecification(Form1 f1)
        {
            InitializeComponent();
            this.f1 = f1;

            string strUI = AppConfigProcess.GetConfigXml("Form3MeterSpecification");//, strI + strU);       //保存电表规格

            if(strUI == "")
            {
                comboBox_Line.SelectedIndex = 0;
            }
            else
            {
                comboBox_Line.SelectedIndex = Convert.ToInt32(AppConfigProcess.GetConfigXml("Form3Line"));
                comboBox_NomalUn.SelectedIndex = Convert.ToInt32(AppConfigProcess.GetConfigXml("Form3NomalUn"));//, comboBox_NomalUn.SelectedIndex.ToString());  //标称电压
                comboBox_NomalImax.SelectedIndex = Convert.ToInt32(AppConfigProcess.GetConfigXml("Form3NomalImax"));//, comboBox_NomalImax.SelectedIndex.ToString());      //保存最大电流
                textBox_Imp.Text = AppConfigProcess.GetConfigXml("Form3Imp");//, textBox_Imp.Text);            //保存脉冲常数
            }

        }

        private void Form3_SetMeterSpecification_Load(object sender, EventArgs e)
        {
            //comboBox_Line.SelectedIndex = 0;
        }

        string  selectedImp()
        {

            string strU = "00";
            string strI = "01";
            if (comboBox_Line.Text == "直接接入")
            {
                if (comboBox_NomalUn.Text == "3×220/380")
                {
                    strU = "00";
                    if (comboBox_NomalImax.Text == "60")
                    {
                        strI = "01";
                        textBox_Imp.Text = "1000";
                    }
                    if (comboBox_NomalImax.Text == "100")
                    {
                        strI = "02";
                        textBox_Imp.Text = "500";
                    }
                }
            }

            if (comboBox_Line.Text == "经互感器接入")
            {
                if (comboBox_NomalUn.Text == "3×220/380")
                {
                    if (comboBox_NomalImax.Text == "6")
                    {
                        textBox_Imp.Text = "10000";
                    }
                    if (comboBox_NomalImax.Text == "1.2")
                    {
                        textBox_Imp.Text = "40000";
                    }
                }

                if (comboBox_NomalUn.Text == "3×57.7/100")
                {
                    strU = "01";
                    if (comboBox_NomalImax.Text == "6")
                    {
                        textBox_Imp.Text = "20000";
                    }
                    if (comboBox_NomalImax.Text == "1.2")
                    {
                        textBox_Imp.Text = "100000";
                    }
                }

                if (comboBox_NomalUn.Text == "3×100")
                {
                    strU = "02";
                    if (comboBox_NomalImax.Text == "6")
                    {
                        textBox_Imp.Text = "20000";
                    }
                    if (comboBox_NomalImax.Text == "1.2")
                    {
                        textBox_Imp.Text = "100000";
                    }
                }

            }


            

            
            return (strI + strU);
        }


        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(comboBox_Line.Text == "直接接入")
            {
                comboBox_NomalUn.Items.Clear();
                comboBox_NomalUn.Items.Add("3×220/380");
                comboBox_NomalUn.SelectedIndex = 0;
                comboBox_NomalImax.Items.Clear();
                comboBox_NomalImax.Items.Add("60");
                comboBox_NomalImax.Items.Add("100");
                comboBox_NomalImax.SelectedIndex = 0;
            }
            else if(comboBox_Line.Text == "经互感器接入")
            {
                comboBox_NomalUn.Items.Clear();
                comboBox_NomalUn.Items.Add("3×220/380");
                comboBox_NomalUn.Items.Add("3×57.7/100");
                comboBox_NomalUn.Items.Add("3×100");
                comboBox_NomalUn.SelectedIndex = 0;
                comboBox_NomalImax.Items.Clear();
                comboBox_NomalImax.Items.Add("6");
                comboBox_NomalImax.Items.Add("1.2");
                comboBox_NomalImax.SelectedIndex = 0;
            }
            else
            {
                comboBox_NomalUn.Items.Clear();
            }

            selectedImp();
        }

        private void comboBox_NomalImax_SelectedIndexChanged(object sender, EventArgs e)
        {
            selectedImp();
        }

        private void comboBox_NomalUn_SelectedIndexChanged(object sender, EventArgs e)
        {
            selectedImp();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            selectedImp();

            AppConfigProcess.SetConfigValue("Form3Line", comboBox_Line.SelectedIndex.ToString());      //接线方式
            AppConfigProcess.SetConfigValue("Form3NomalUn", comboBox_NomalUn.SelectedIndex.ToString());  //标称电压
            AppConfigProcess.SetConfigValue("Form3NomalImax", comboBox_NomalImax.SelectedIndex.ToString());      //保存最大电流
            AppConfigProcess.SetConfigValue("Form3Imp", textBox_Imp.Text);            //保存脉冲常数
            AppConfigProcess.SetConfigValue("Form3MeterSpecification", selectedImp());       //保存电表规格
            this.Close();
        }
    }
}
